﻿package mortal.game.view.common
{
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import mortal.common.cd.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;

    public class SecTimerView extends GTextFiled
    {
        protected var _secTimerViewData:SecTimerViewData;
        protected var _strParse:String = "mm:ss";
        protected var _timeOutCallBack:Function;
        protected var _colorChange:Array;
        private var _updateCount:int;
        private var _curColorIndex:int;
        private var _curColor:String;

        public function SecTimerView()
        {
            return;
        }// end function

        public function setLeftTime(param1:int, param2:Boolean = true) : void
        {
            if (param1 < 0)
            {
                param1 = 0;
            }
            if (!this._secTimerViewData)
            {
                this._secTimerViewData = new SecTimerViewData();
            }
            this._secTimerViewData.setLeftTime(param1, param2);
            this._secTimerViewData.caller = this.update;
            if (this._timeOutCallBack != null)
            {
                this._secTimerViewData.timeOutCaller = this._timeOutCallBack;
            }
            this.update();
            return;
        }// end function

        public function getLeftTime() : int
        {
            if (this._secTimerViewData)
            {
                return this._secTimerViewData.leftTime;
            }
            return 0;
        }// end function

        public function stop() : void
        {
            if (this._secTimerViewData)
            {
                this._secTimerViewData.stop();
            }
            return;
        }// end function

        protected function update() : void
        {
            var _loc_1:String = null;
            var _loc_2:String = this;
            var _loc_3:* = this._updateCount + 1;
            _loc_2._updateCount = _loc_3;
            if (this._colorChange && this._colorChange.length > 0)
            {
                this._curColorIndex = this._updateCount % this._colorChange.length;
                this._curColor = this._colorChange[this._curColorIndex];
            }
            if (this._curColor)
            {
                this.htmlText = HTMLUtil.addColor(this._secTimerViewData.parse(this._strParse), this._curColor);
            }
            else
            {
                _loc_1 = this._secTimerViewData.parse(this._strParse);
                this.htmlText = _loc_1;
            }
            this.dispatchEvent(new DataEvent(EventName.SecViewTimeChange, this._secTimerViewData.leftTime));
            return;
        }// end function

        public function setParse(param1:String) : void
        {
            this._strParse = param1;
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            if (this._secTimerViewData)
            {
                this._secTimerViewData.dispose();
            }
            this._secTimerViewData = null;
            this._colorChange = null;
            this._timeOutCallBack = null;
            this._updateCount = 0;
            this._curColorIndex = 0;
            this._curColor = null;
            defaultTextFormat = GlobalStyle.textFormatHuang;
            this.styleSheet = null;
            this.text = "";
            this.htmlText = "";
            this._strParse = "";
            this.setTextFormat(this.defaultTextFormat);
            super.dispose(param1);
            return;
        }// end function

        public function changeCheckLabel(param1:String, param2:String) : void
        {
            if (!this._secTimerViewData)
            {
                this._secTimerViewData = new SecTimerViewData();
            }
            this._secTimerViewData.changeCheckLabel(param1, param2);
            return;
        }// end function

        public function get secTimerViewData() : SecTimerViewData
        {
            return this._secTimerViewData;
        }// end function

        public function set timeOutHandler(param1:Function) : void
        {
            this._timeOutCallBack = param1;
            if (this._secTimerViewData)
            {
                this._secTimerViewData.timeOutCaller = this._timeOutCallBack;
            }
            return;
        }// end function

        public function set colorChange(param1:Array) : void
        {
            this._colorChange = param1;
            return;
        }// end function

        public function get colorChange() : Array
        {
            return this._colorChange;
        }// end function

        public function get running() : Boolean
        {
            if (this._secTimerViewData)
            {
                return this._secTimerViewData.running;
            }
            return false;
        }// end function

        public function get parse() : String
        {
            return this._strParse;
        }// end function

    }
}
